<?php
require_once('init.php');

$controllers = array (
	'isLoggedIn' => array (
		'nieuwsitem' => array (
			'single',
			'list',
			'delete',
			'add',
			'edit',
		),
		'gebruiker' => array (
			'logout',
		),
		'product' => array (
			'list',
			'single',
			'winkelwagen',
			'koppel',
			'bedrijfkoppel',
			'medewerkerkoppel',
			'ontkoppel',
			'delete',
			'subproduct'
		),
		'paneel' => array (
			'www',
			'notificatieinstelling',
			'xml',
			'userpanel',
			'wijzigwachtwoord',
		),
		'productlijst' => array (
			'upload',
			'add',
			'import',
			'list',
			'edit',
			'delete',
			'single',
			'koppel',
			'ontkoppel',
		),
		'groothandel' => array (
			'single',
			'list',
			'delete',
			'add',
			'edit',
			'overzichten',
			'overzichtenform',
		),
		'bedrijf' => array (
			'single',
			'list',
			'delete',
			'add',
			'edit',
			'overzichten',
			'overzichtenform',
		),
		'medewerker' => array (
			'single',
			'list',
			'delete',
			'add',
			'edit',
			'overzichten',
		),
		'bestelling' => array (
			'add',
			'list',
			'single'
		),
	),
	'notLoggedIn' => array (
		'gebruiker' => array (
			'login',
			'forgotpass',
		),
		'error' => array(
			'notfound'
		)
	),
);

function renderPage($controller, $page, $multiColumns = false, $includeNav = true)
{
	require_once(APP_TPL_PATH . 'header.php');
	require_once(APP_VIEW_PATH . $controller . DS . $controller . '.' . $page . '.php');
	require_once(APP_TPL_PATH . 'footer.php');
}

if (Login::isLoggedIn())
{
	if ((isset($_GET['c']) && isset($_GET['p'])))
		if ((array_key_exists($_GET['c'], $controllers['isLoggedIn'])) &&
				(array_search($_GET['p'], $controllers['isLoggedIn'][$_GET['c']]) !== false))
			renderPage($_GET['c'], $_GET['p'], false);
		else
			renderPage('error', 'notfound', false);
	else if(isset($_GET['c']) && !isset($_GET['p']))
		renderPage('error', 'notfound', false);
	else if(!isset($_GET['c']) && isset($_GET['p']))
		renderPage('error', 'notfound', false);
	else
		renderPage('nieuwsitem', 'single', ($_SESSION['GroepID'] == 4) ? false : true);
}
else
	if ((!empty($_GET['c']) && !empty($_GET['p'])))
	{
		if ((array_key_exists($_GET['c'], $controllers['notLoggedIn'])) &&
				(array_search($_GET['p'], $controllers['notLoggedIn'][$_GET['c']]) !== false))
				renderPage($_GET['c'], $_GET['p'], false, false);
		else
			renderPage('error', 'notfound', false);
	}
	else if(!empty($_GET['c']) && empty($_GET['p']))
		renderPage('error', 'notfound', false);
	else if(empty($_GET['c']) && !empty($_GET['p']))
		renderPage('error', 'notfound', false);
	else
		renderPage('gebruiker', 'login', false, false);



?>
